package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    /*
     * 插入订单数据
     */
    void insert(Orders order);

    /*
     * 查询历史订单
     * */
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    // 根据id查询订单
    @Select( "select * from sky_take_out.orders where id=#{id}" )
    Orders getById(Long id);

    /*
     *  修改订单信息
     * */
    void update(Orders orders);


    @Select("select * from sky_take_out.orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String outTradeNo, Long userId);

    /*
     * 各个状态的订单数量统计
     * */
    @Select("select  count(id) from sky_take_out.orders where status =#{status}")
    Integer countStatus(Integer toBeConfirmed);


    /*
     * 根据状态和下单时间查询订单
     */
    @Select("select * from sky_take_out.orders where status = #{status} and order_time < #{orderTime}")
    List<Orders> getByStatusAndOrdertimeLT(Integer status, LocalDateTime orderTime);

    /*
     * 根据时间区间统计营业额
     */
    Double sumByMap(Map map);
    /*
     *根据动态条件统计订单数量
     */
    Integer countByMap(Map map);

    List<GoodsSalesDTO> getSalesTop10(LocalDateTime beginTime, LocalDateTime endTime);
}
